<?php
declare(strict_types=1);

namespace SixShop\Payment\Hook;

use app\model\Order;
use SixShop\Core\Attribute\Hook;
use SixShop\Payment\Enum\PaymentBizEnum;
use SixShop\Payment\Event\PaymentSuccessEvent;

class OrderHook
{

    #[Hook(PaymentSuccessEvent::class)]
    public function onPaymentSuccess(PaymentSuccessEvent $event): void
    {
        if ($event->bizType != PaymentBizEnum::ORDER_PAY) {
            return;
        }
        $order = Order::find($event->payment['order_id']);
        $order->save([
            'pay_time' => date('Y-m-d H:i:s'),
            'pay_status' => 1, //已支付
            'order_status' => 20, //待发货
        ]);
    }
}